package com.haofengsoft.scce.db.biz.consultation;

import java.util.List;

import android.content.Context;

import com.haofengsoft.scce.ManageApplication;
import com.haofengsoft.scce.db.DaoSession;
import com.haofengsoft.scce.db.bean.AttentionItem;
import com.haofengsoft.scce.db.dao.consultation.AttentionItemDao;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by admin on 2015/7/22.
 */
public class AttentionItemBiz {
    private static AttentionItemBiz instance;
    private static Context appContext;
    private AttentionItemDao dao;

    private AttentionItemBiz() {
    }

    public static AttentionItemBiz getInstance(Context context) {
        if (instance == null) {
            instance = new AttentionItemBiz();
            if (appContext == null) {
                appContext = context.getApplicationContext();
            }
            DaoSession daoSession = ManageApplication.getDaoSession(context);
            instance.dao = daoSession.getAttentionItemDao();
        }
        return instance;
    }

    //获取选中的
    public List<AttentionItem> gainCheckAttentionList() {
        QueryBuilder qb = dao.queryBuilder();
        qb.where(AttentionItemDao.Properties.AttentionChecked.eq(1));
        qb.orderAsc(AttentionItemDao.Properties.OrderIndex);
        return qb.list();
    }

    //获取所有的
    public List<AttentionItem> gainAttentionAll() {
        QueryBuilder qb = dao.queryBuilder();
        qb.orderAsc(AttentionItemDao.Properties.OrderIndex);
        return qb.list();
    }
    //标注，更改选中，以及排序,没有选中的默认 1000

    public void insertAttentionList(List<AttentionItem> attentionItemList) {
        try {
            for (AttentionItem item : attentionItemList) {

                dao.insertOrReplace(item);
            }
        } catch (Exception e) {
            System.out.println("结果" + e.getMessage());
        }
    }


}
